<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>GApplication</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
<link rel="home" href="index.html" title="GIO 参考手册">
<link rel="up" href="application.html" title="Application support">
<link rel="prev" href="gio-GSimpleAction.html" title="GSimpleAction">
<link rel="next" href="gio-GApplicationCommandLine.html" title="GApplicationCommandLine">
<meta name="generator" content="GTK-Doc V1.17 (XML mode)">
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2">
<tr valign="middle">
<td><a accesskey="p" href="gio-GSimpleAction.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td>
<td><a accesskey="u" href="application.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td>
<td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td>
<th width="100%" align="center">GIO 参考手册</th>
<td><a accesskey="n" href="gio-GApplicationCommandLine.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td>
</tr>
<tr><td colspan="5" class="shortcuts">
<a href="#gio-GApplication.synopsis" class="shortcut">Top</a>
                   | 
                  <a href="#gio-GApplication.description" class="shortcut">Description</a>
</td></tr>
</table>
<div class="refentry">
<a name="gio-GApplication"></a><div class="titlepage"></div>
<div class="refnamediv"><table width="100%"><tr>
<td valign="top">
<h2><span class="refentrytitle"><a name="gio-GApplication.top_of_page"></a>GApplication</span></h2>
<p>GApplication — Core application class</p>
</td>
<td valign="top" align="right"></td>
</tr></table></div>
<div class="refsynopsisdiv">
<a name="gio-GApplication.synopsis"></a><h2>Synopsis</h2>
<pre class="synopsis">                    <a class="link" href="gio-GApplication.html#GApplication" title="GApplication">GApplication</a>;
struct              <a class="link" href="gio-GApplication.html#GApplicationClass" title="struct GApplicationClass">GApplicationClass</a>;

enum                <a class="link" href="gio-GApplication.html#GApplicationFlags" title="enum GApplicationFlags">GApplicationFlags</a>;
<a href="../glib/glib-Basic-Types.html#gboolean"><span class="returnvalue">gboolean</span></a>            <a class="link" href="gio-GApplication.html#g-application-id-is-valid" title="g_application_id_is_valid ()">g_application_id_is_valid</a>           (<em class="parameter"><code>const <a href="../glib/glib-Basic-Types.html#gchar"><span class="type">gchar</span></a> *application_id</code></em>);
<a class="link" href="gio-GApplication.html#GApplication" title="GApplication"><span class="returnvalue">GApplication</span></a> *           <a class="link" href="gio-GApplication.html#g-application-new" title="g_application_new ()">g_application_new</a>              (<em class="parameter"><code>const <a href="../glib/glib-Basic-Types.html#gchar"><span class="type">gchar</span></a> *application_id</code></em>,
                                                         <em class="parameter"><code><a class="link" href="gio-GApplication.html#GApplicationFlags" title="enum GApplicationFlags"><span class="type">GApplicationFlags</span></a> flags</code></em>);

const <a href="../glib/glib-Basic-Types.html#gchar"><span class="returnvalue">gchar</span></a> *            <a class="link" href="gio-GApplication.html#g-application-get-application-id" title="g_application_get_application_id ()">g_application_get_application_id</a>
                                                        (<em class="parameter"><code><a class="link" href="gio-GApplication.html#GApplication" title="GApplication"><span class="type">GApplication</span></a> *application</code></em>);
<span class="returnvalue">void</span>                <a class="link" href="gio-GApplication.html#g-application-set-application-id" title="g_application_set_application_id ()">g_application_set_application_id</a>    (<em class="parameter"><code><a class="link" href="gio-GApplication.html#GApplication" title="GApplication"><span class="type">GApplication</span></a> *application</code></em>,
                                                         <em class="parameter"><code>const <a href="../glib/glib-Basic-Types.html#gchar"><span class="type">gchar</span></a> *application_id</code></em>);

<a href="../glib/glib-Basic-Types.html#guint"><span class="returnvalue">guint</span></a>               <a class="link" href="gio-GApplication.html#g-application-get-inactivity-timeout" title="g_application_get_inactivity_timeout ()">g_application_get_inactivity_timeout</a>
                                                        (<em class="parameter"><code><a class="link" href="gio-GApplication.html#GApplication" title="GApplication"><span class="type">GApplication</span></a> *application</code></em>);
<span class="returnvalue">void</span>                <a class="link" href="gio-GApplication.html#g-application-set-inactivity-timeout" title="g_application_set_inactivity_timeout ()">g_application_set_inactivity_timeout</a>
                                                        (<em class="parameter"><code><a class="link" href="gio-GApplication.html#GApplication" title="GApplication"><span class="type">GApplication</span></a> *application</code></em>,
                                                         <em class="parameter"><code><a href="../glib/glib-Basic-Types.html#guint"><span class="type">guint</span></a> inactivity_timeout</code></em>);

<a class="link" href="gio-GApplication.html#GApplicationFlags" title="enum GApplicationFlags"><span class="returnvalue">GApplicationFlags</span></a>   <a class="link" href="gio-GApplication.html#g-application-get-flags" title="g_application_get_flags ()">g_application_get_flags</a>             (<em class="parameter"><code><a class="link" href="gio-GApplication.html#GApplication" title="GApplication"><span class="type">GApplication</span></a> *application</code></em>);
<span class="returnvalue">void</span>                <a class="link" href="gio-GApplication.html#g-application-set-flags" title="g_application_set_flags ()">g_application_set_flags</a>             (<em class="parameter"><code><a class="link" href="gio-GApplication.html#GApplication" title="GApplication"><span class="type">GApplication</span></a> *application</code></em>,
                                                         <em class="parameter"><code><a class="link" href="gio-GApplication.html#GApplicationFlags" title="enum GApplicationFlags"><span class="type">GApplicationFlags</span></a> flags</code></em>);

<span class="returnvalue">void</span>                <a class="link" href="gio-GApplication.html#g-application-set-action-group" title="g_application_set_action_group ()">g_application_set_action_group</a>      (<em class="parameter"><code><a class="link" href="gio-GApplication.html#GApplication" title="GApplication"><span class="type">GApplication</span></a> *application</code></em>,
                                                         <em class="parameter"><code><a class="link" href="gio-GActionGroup.html#GActionGroup" title="GActionGroup"><span class="type">GActionGroup</span></a> *action_group</code></em>);

<a href="../glib/glib-Basic-Types.html#gboolean"><span class="returnvalue">gboolean</span></a>            <a class="link" href="gio-GApplication.html#g-application-get-is-registered" title="g_application_get_is_registered ()">g_application_get_is_registered</a>     (<em class="parameter"><code><a class="link" href="gio-GApplication.html#GApplication" title="GApplication"><span class="type">GApplication</span></a> *application</code></em>);
<a href="../glib/glib-Basic-Types.html#gboolean"><span class="returnvalue">gboolean</span></a>            <a class="link" href="gio-GApplication.html#g-application-get-is-remote" title="g_application_get_is_remote ()">g_application_get_is_remote</a>         (<em class="parameter"><code><a class="link" href="gio-GApplication.html#GApplication" title="GApplication"><span class="type">GApplication</span></a> *application</code></em>);
<a href="../glib/glib-Basic-Types.html#gboolean"><span class="returnvalue">gboolean</span></a>            <a class="link" href="gio-GApplication.html#g-application-register" title="g_application_register ()">g_application_register</a>              (<em class="parameter"><code><a class="link" href="gio-GApplication.html#GApplication" title="GApplication"><span class="type">GApplication</span></a> *application</code></em>,
                                                         <em class="parameter"><code><a class="link" href="gio-GCancellable.html#GCancellable" title="GCancellable"><span class="type">GCancellable</span></a> *cancellable</code></em>,
                                                         <em class="parameter"><code><a href="../glib/glib-Error-Reporting.html#GError"><span class="type">GError</span></a> **error</code></em>);

<span class="returnvalue">void</span>                <a class="link" href="gio-GApplication.html#g-application-hold" title="g_application_hold ()">g_application_hold</a>                  (<em class="parameter"><code><a class="link" href="gio-GApplication.html#GApplication" title="GApplication"><span class="type">GApplication</span></a> *application</code></em>);
<span class="returnvalue">void</span>                <a class="link" href="gio-GApplication.html#g-application-release" title="g_application_release ()">g_application_release</a>               (<em class="parameter"><code><a class="link" href="gio-GApplication.html#GApplication" title="GApplication"><span class="type">GApplication</span></a> *application</code></em>);

<span class="returnvalue">void</span>                <a class="link" href="gio-GApplication.html#g-application-activate" title="g_application_activate ()">g_application_activate</a>              (<em class="parameter"><code><a class="link" href="gio-GApplication.html#GApplication" title="GApplication"><span class="type">GApplication</span></a> *application</code></em>);
<span class="returnvalue">void</span>                <a class="link" href="gio-GApplication.html#g-application-open" title="g_application_open ()">g_application_open</a>                  (<em class="parameter"><code><a class="link" href="gio-GApplication.html#GApplication" title="GApplication"><span class="type">GApplication</span></a> *application</code></em>,
                                                         <em class="parameter"><code><a class="link" href="gio-GFile.html#GFile" title="GFile"><span class="type">GFile</span></a> **files</code></em>,
                                                         <em class="parameter"><code><a href="../glib/glib-Basic-Types.html#gint"><span class="type">gint</span></a> n_files</code></em>,
                                                         <em class="parameter"><code>const <a href="../glib/glib-Basic-Types.html#gchar"><span class="type">gchar</span></a> *hint</code></em>);

<span class="returnvalue">int</span>                 <a class="link" href="gio-GApplication.html#g-application-run" title="g_application_run ()">g_application_run</a>                   (<em class="parameter"><code><a class="link" href="gio-GApplication.html#GApplication" title="GApplication"><span class="type">GApplication</span></a> *application</code></em>,
                                                         <em class="parameter"><code><span class="type">int</span> argc</code></em>,
                                                         <em class="parameter"><code><span class="type">char</span> **argv</code></em>);
</pre>
</div>
<div class="refsect1">
<a name="gio-GApplication.description"></a><h2>Description</h2>
<p>
A <a class="link" href="gio-GApplication.html#GApplication" title="GApplication"><span class="type">GApplication</span></a> is the foundation of an application, unique for a
given application identifier.  The GApplication class wraps some
low-level platform-specific services and is intended to act as the
foundation for higher-level application classes such as
<span class="type">GtkApplication</span> or <span class="type">MxApplication</span>.  In general, you should not use
this class outside of a higher level framework.
</p>
<p>
One of the core features that GApplication provides is process
uniqueness, in the context of a "session".  The session concept is
platform-dependent, but corresponds roughly to a graphical desktop
login.  When your application is launched again, its arguments
are passed through platform communication to the already running
program. The already running instance of the program is called the
<em class="firstterm">primary instance</em>.
</p>
<p>
Before using GApplication, you must choose an "application identifier".
The expected form of an application identifier is very close to that of
of a <a class="ulink" href="http://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names-interface" target="_top">DBus bus name</a>.
Examples include: "com.example.MyApp", "org.example.internal-apps.Calculator".
For details on valid application identifiers, see
<a class="link" href="gio-GApplication.html#g-application-id-is-valid" title="g_application_id_is_valid ()"><code class="function">g_application_id_is_valid()</code></a>.
</p>
<p>
The application identifier is claimed by the application as a
well-known bus name on the user's session bus.  This means that the
uniqueness of your application is scoped to the current session.  It
also means that your application may provide additional services
(through registration of other object paths) at that bus name.
</p>
<p>
The registration of these object paths should be done with the shared
GDBus session bus.  Note that due to the internal architecture of
GDBus, method calls can be dispatched at any time (even if a main
loop is not running).  For this reason, you must ensure that any
object paths that you wish to register are registered before
<a class="link" href="gio-GApplication.html#GApplication" title="GApplication"><span class="type">GApplication</span></a> attempts to acquire the bus name of your application
(which happens in <a class="link" href="gio-GApplication.html#g-application-register" title="g_application_register ()"><code class="function">g_application_register()</code></a>).  Unfortunately, this
means that you can not use <a class="link" href="gio-GApplication.html#g-application-get-is-remote" title="g_application_get_is_remote ()"><code class="function">g_application_get_is_remote()</code></a> to decide if
you want to register object paths.
</p>
<p>
GApplication provides convenient life cycle management by maintaining
a <em class="firstterm">use count</em> for the primary application instance.
The use count can be changed using <a class="link" href="gio-GApplication.html#g-application-hold" title="g_application_hold ()"><code class="function">g_application_hold()</code></a> and
<a class="link" href="gio-GApplication.html#g-application-release" title="g_application_release ()"><code class="function">g_application_release()</code></a>. If it drops to zero, the application exits.
</p>
<p>
GApplication also implements the <a class="link" href="gio-GActionGroup.html#GActionGroup" title="GActionGroup"><span class="type">GActionGroup</span></a> interface and lets you
easily export actions by adding them with <a class="link" href="gio-GApplication.html#g-application-set-action-group" title="g_application_set_action_group ()"><code class="function">g_application_set_action_group()</code></a>.
When invoking an action by calling <a class="link" href="gio-GActionGroup.html#g-action-group-activate-action" title="g_action_group_activate_action ()"><code class="function">g_action_group_activate_action()</code></a> on
the application, it is always invoked in the primary instance.
</p>
<p>
There is a number of different entry points into a <a class="link" href="gio-GApplication.html#GApplication" title="GApplication"><span class="type">GApplication</span></a>:
</p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem">via 'Activate' (i.e. just starting the application)</li>
<li class="listitem">via 'Open' (i.e. opening some files)</li>
<li class="listitem">by handling a command-line</li>
<li class="listitem">via activating an action</li>
</ul></div>
<p>
The <span class="type">"startup"</span> signal lets you handle the application
initialization for all of these in a single place.
</p>
<p>
Regardless of which of these entry points is used to start the application,
GApplication passes some <em class="firstterm"><a name="platform-data"></a>platform
data</em> from the launching instance to the primary instance,
in the form of a <a href="../glib/glib-GVariant.html#GVariant"><span class="type">GVariant</span></a> dictionary mapping strings to variants.
To use platform data, override the <em class="parameter"><code>before_emit</code></em> or <em class="parameter"><code>after_emit</code></em> virtual
functions in your <a class="link" href="gio-GApplication.html#GApplication" title="GApplication"><span class="type">GApplication</span></a> subclass. When dealing with
<span class="type">GApplicationCommandline</span> objects, the platform data is directly
available via <a class="link" href="gio-GApplicationCommandLine.html#g-application-command-line-get-cwd" title="g_application_command_line_get_cwd ()"><code class="function">g_application_command_line_get_cwd()</code></a>,
<a class="link" href="gio-GApplicationCommandLine.html#g-application-command-line-get-environ" title="g_application_command_line_get_environ ()"><code class="function">g_application_command_line_get_environ()</code></a> and
<a class="link" href="gio-GApplicationCommandLine.html#g-application-command-line-get-platform-data" title="g_application_command_line_get_platform_data ()"><code class="function">g_application_command_line_get_platform_data()</code></a>.
</p>
<p>
As the name indicates, the platform data may vary depending on the
operating system, but it always includes the current directory (key
"cwd"), and optionally the environment (ie the set of environment
variables and their values) of the calling process (key "environ").
The environment is only added to the platform data if the
<span class="type">G_APPLICATION_SEND_ENVIONMENT</span> flag is set. GApplication subclasses
can add their own platform data by overriding the <em class="parameter"><code>add_platform_data</code></em>
virtual function. For instance, <span class="type">GtkApplication</span> adds startup notification
data in this way.
</p>
<p>
To parse commandline arguments you may handle the
<span class="type">"command-line"</span> signal or override the <code class="function">local_command_line()</code>
vfunc, to parse them in either the primary instance or the local instance,
respectively.
</p>
<p>
</p>
<div class="example">
<a name="gapplication-example-open"></a><p class="title"><b>Example 13. Opening files with a GApplication</b></p>
<div class="example-contents"><pre class="programlisting">
#include &lt;gio/gio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;string.h&gt;

static void
activate (GApplication *application)
{
  g_print ("activated\n");

  /* Note: when doing a longer-lasting action here that returns
   * to the mainloop, you should use g_application_hold() and
   * g_application_release() to keep the application alive until
   * the action is completed.
   */
}

static void
open (GApplication  *application,
      GFile        **files,
      gint           n_files,
      const gchar   *hint)
{
  gint i;

  for (i = 0; i &lt; n_files; i++)
    {
      gchar *uri = g_file_get_uri (files[i]);
      g_print ("open %s\n", uri);
      g_free (uri);
    }

  /* Note: when doing a longer-lasting action here that returns
   * to the mainloop, you should use g_application_hold() and
   * g_application_release() to keep the application alive until
   * the action is completed.
   */
}

int
main (int argc, char **argv)
{
  GApplication *app;
  int status;

  app = g_application_new ("org.gtk.TestApplication",
                           G_APPLICATION_HANDLES_OPEN);
  g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
  g_signal_connect (app, "open", G_CALLBACK (open), NULL);
  g_application_set_inactivity_timeout (app, 10000);

  status = g_application_run (app, argc, argv);

  g_object_unref (app);

  return status;
}

</pre></div>
</div>
<p><br class="example-break">
</p>
<p>
</p>
<div class="example">
<a name="gapplication-example-actions"></a><p class="title"><b>Example 14. A GApplication with actions</b></p>
<div class="example-contents"><pre class="programlisting">
#include &lt;gio/gio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;string.h&gt;

static void
activate (GApplication *application)
{
  g_print ("activated\n");
}

static void
activate_action (GAction  *action,
                 GVariant *parameter,
                 gpointer  data)
{
  g_print ("action %s activated\n", g_action_get_name (action));
}

static void
activate_toggle_action (GAction  *action,
                        GVariant *parameter,
                        gpointer  data)
{
  GVariant *state;
  gboolean b;

  g_print ("action %s activated\n", g_action_get_name (action));

  state = g_action_get_state (action);
  b = g_variant_get_boolean (state);
  g_variant_unref (state);
  g_action_set_state (action, g_variant_new_boolean (!b));
  g_print ("state change %d -&gt; %d\n", b, !b);
}

static void
add_actions (GApplication *app)
{
  GSimpleActionGroup *actions;
  GSimpleAction *action;

  actions = g_simple_action_group_new ();

  action = g_simple_action_new ("simple-action", NULL);
  g_signal_connect (action, "activate", G_CALLBACK (activate_action), app);
  g_simple_action_group_insert (actions, G_ACTION (action));
  g_object_unref (action);

  action = g_simple_action_new_stateful ("toggle-action", NULL,
                                         g_variant_new_boolean (FALSE));
  g_signal_connect (action, "activate", G_CALLBACK (activate_toggle_action), app);
  g_simple_action_group_insert (actions, G_ACTION (action));
  g_object_unref (action);

  g_application_set_action_group (app, G_ACTION_GROUP (actions));
  g_object_unref (actions);
}

int
main (int argc, char **argv)
{
  GApplication *app;
  int status;

  app = g_application_new ("org.gtk.TestApplication", 0);
  g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
  g_application_set_inactivity_timeout (app, 10000);

  add_actions (app);

  if (argc &gt; 1 &amp;&amp; strcmp (argv[1], "--simple-action") == 0)
    {
      g_application_register (app, NULL, NULL);
      g_action_group_activate_action (G_ACTION_GROUP (app), "simple-action", NULL);
      exit (0);
    }
  else if (argc &gt; 1 &amp;&amp; strcmp (argv[1], "--toggle-action") == 0)
    {
      g_application_register (app, NULL, NULL);
      g_action_group_activate_action (G_ACTION_GROUP (app), "toggle-action", NULL);
      exit (0);
    }

  status = g_application_run (app, argc, argv);

  g_object_unref (app);

  return status;
}

</pre></div>
</div>
<p><br class="example-break">
</p>
</div>
<div class="refsect1">
<a name="gio-GApplication.details"></a><h2>Details</h2>
<div class="refsect2">
<a name="GApplication"></a><h3>GApplication</h3>
<pre class="programlisting">typedef struct {
} GApplication;
</pre>
<p>
The <span class="structname">GApplication</span> structure contains private
data and should only be accessed using the provided API
</p>
<p class="since">Since 2.28</p>
</div>
<hr>
<div class="refsect2">
<a name="GApplicationClass"></a><h3>struct GApplicationClass</h3>
<pre class="programlisting">struct GApplicationClass {
  /* signals */
  void                      (* startup)             (GApplication              *application);

  void                      (* activate)            (GApplication              *application);

  void                      (* open)                (GApplication              *application,
                                                     GFile                    **files,
                                                     gint                       n_files,
                                                     const gchar               *hint);

  int                       (* command_line)        (GApplication              *application,
                                                     GApplicationCommandLine   *command_line);

  /* vfuncs */
  gboolean                  (* local_command_line)  (GApplication              *application,
                                                     gchar                   ***arguments,
                                                     int                       *exit_status);

  void                      (* before_emit)         (GApplication              *application,
                                                     GVariant                  *platform_data);
  void                      (* after_emit)          (GApplication              *application,
                                                     GVariant                  *platform_data);
  void                      (* add_platform_data)   (GApplication              *application,
                                                     GVariantBuilder           *builder);
  void                      (* quit_mainloop)       (GApplication              *application);
  void                      (* run_mainloop)        (GApplication              *application);
};
</pre>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="structfield"><code><a name="GApplicationClass.startup"></a>startup</code></em> ()</span></p></td>
<td>invoked on the primary instance immediately after registration</td>
</tr>
<tr>
<td><p><span class="term"><em class="structfield"><code><a name="GApplicationClass.activate"></a>activate</code></em> ()</span></p></td>
<td>invoked on the primary instance when an activation occurs</td>
</tr>
<tr>
<td><p><span class="term"><em class="structfield"><code><a name="GApplicationClass.open"></a>open</code></em> ()</span></p></td>
<td>invoked on the primary instance when there are files to open</td>
</tr>
<tr>
<td><p><span class="term"><em class="structfield"><code><a name="GApplicationClass.command-line"></a>command_line</code></em> ()</span></p></td>
<td>invoked on the primary instance when a command-line is
not handled locally</td>
</tr>
<tr>
<td><p><span class="term"><em class="structfield"><code><a name="GApplicationClass.local-command-line"></a>local_command_line</code></em> ()</span></p></td>
<td>invoked (locally) when the process has been invoked
via commandline execution.  The virtual function has the chance to
inspect (and possibly replace) the list of command line arguments.
See <a class="link" href="gio-GApplication.html#g-application-run" title="g_application_run ()"><code class="function">g_application_run()</code></a> for more information.</td>
</tr>
<tr>
<td><p><span class="term"><em class="structfield"><code><a name="GApplicationClass.before-emit"></a>before_emit</code></em> ()</span></p></td>
<td>invoked on the primary instance before 'activate', 'open',
'command-line' or any action invocation, gets the 'platform data' from
the calling instance</td>
</tr>
<tr>
<td><p><span class="term"><em class="structfield"><code><a name="GApplicationClass.after-emit"></a>after_emit</code></em> ()</span></p></td>
<td>invoked on the primary instance after 'activate', 'open',
'command-line' or any action invocation, gets the 'platform data' from
the calling instance</td>
</tr>
<tr>
<td><p><span class="term"><em class="structfield"><code><a name="GApplicationClass.add-platform-data"></a>add_platform_data</code></em> ()</span></p></td>
<td>invoked (locally) to add 'platform data' to be sent to
the primary instance when activating, opening or invoking actions</td>
</tr>
<tr>
<td><p><span class="term"><em class="structfield"><code><a name="GApplicationClass.quit-mainloop"></a>quit_mainloop</code></em> ()</span></p></td>
<td>invoked on the primary instance when the use count of the
application drops to zero (and after any inactivity timeout, if
requested)</td>
</tr>
<tr>
<td><p><span class="term"><em class="structfield"><code><a name="GApplicationClass.run-mainloop"></a>run_mainloop</code></em> ()</span></p></td>
<td>invoked on the primary instance from <a class="link" href="gio-GApplication.html#g-application-run" title="g_application_run ()"><code class="function">g_application_run()</code></a>
if the use-count is non-zero</td>
</tr>
</tbody>
</table></div>
<p class="since">Since 2.28</p>
</div>
<hr>
<div class="refsect2">
<a name="GApplicationFlags"></a><h3>enum GApplicationFlags</h3>
<pre class="programlisting">typedef enum
{
  G_APPLICATION_FLAGS_NONE,
  G_APPLICATION_IS_SERVICE  =          (1 &lt;&lt; 0),
  G_APPLICATION_IS_LAUNCHER =          (1 &lt;&lt; 1),

  G_APPLICATION_HANDLES_OPEN =         (1 &lt;&lt; 2),
  G_APPLICATION_HANDLES_COMMAND_LINE = (1 &lt;&lt; 3),
  G_APPLICATION_SEND_ENVIRONMENT    =  (1 &lt;&lt; 4)
} GApplicationFlags;
</pre>
<p>
Flags used to define the behaviour of a <a class="link" href="gio-GApplication.html#GApplication" title="GApplication"><span class="type">GApplication</span></a>.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><a name="G-APPLICATION-FLAGS-NONE:CAPS"></a><span class="term"><code class="literal">G_APPLICATION_FLAGS_NONE</code></span></p></td>
<td>Default
</td>
</tr>
<tr>
<td><p><a name="G-APPLICATION-IS-SERVICE:CAPS"></a><span class="term"><code class="literal">G_APPLICATION_IS_SERVICE</code></span></p></td>
<td>Run as a service. In this mode, registration
     fails if the service is already running, and the application will
     stay around for a while when the use count falls to zero.
</td>
</tr>
<tr>
<td><p><a name="G-APPLICATION-IS-LAUNCHER:CAPS"></a><span class="term"><code class="literal">G_APPLICATION_IS_LAUNCHER</code></span></p></td>
<td>Don't try to become the primary instance.
</td>
</tr>
<tr>
<td><p><a name="G-APPLICATION-HANDLES-OPEN:CAPS"></a><span class="term"><code class="literal">G_APPLICATION_HANDLES_OPEN</code></span></p></td>
<td>This application handles opening files (in
    the primary instance). Note that this flag only affects the default
    implementation of <code class="function">local_command_line()</code>, and has no effect if
    <a class="link" href="gio-GApplication.html#G-APPLICATION-HANDLES-COMMAND-LINE:CAPS"><code class="literal">G_APPLICATION_HANDLES_COMMAND_LINE</code></a> is given.
    See <a class="link" href="gio-GApplication.html#g-application-run" title="g_application_run ()"><code class="function">g_application_run()</code></a> for details.
</td>
</tr>
<tr>
<td><p><a name="G-APPLICATION-HANDLES-COMMAND-LINE:CAPS"></a><span class="term"><code class="literal">G_APPLICATION_HANDLES_COMMAND_LINE</code></span></p></td>
<td>This application handles command line
    arguments (in the primary instance). Note that this flag only affect
    the default implementation of <code class="function">local_command_line()</code>.
    See <a class="link" href="gio-GApplication.html#g-application-run" title="g_application_run ()"><code class="function">g_application_run()</code></a> for details.
</td>
</tr>
<tr>
<td><p><a name="G-APPLICATION-SEND-ENVIRONMENT:CAPS"></a><span class="term"><code class="literal">G_APPLICATION_SEND_ENVIRONMENT</code></span></p></td>
<td>Send the environment of the
    launching process to the primary instance. Set this flag if your
    application is expected to behave differently depending on certain
    environment variables. For instance, an editor might be expected
    to use the <code class="envar">GIT_COMMITTER_NAME</code> environment variable
    when editing a git commit message. The environment is available
    to the <span class="type">"command-line"</span> signal handler, via
    <a class="link" href="gio-GApplicationCommandLine.html#g-application-command-line-getenv" title="g_application_command_line_getenv ()"><code class="function">g_application_command_line_getenv()</code></a>.
</td>
</tr>
</tbody>
</table></div>
<p class="since">Since 2.28</p>
</div>
<hr>
<div class="refsect2">
<a name="g-application-id-is-valid"></a><h3>g_application_id_is_valid ()</h3>
<pre class="programlisting"><a href="../glib/glib-Basic-Types.html#gboolean"><span class="returnvalue">gboolean</span></a>            g_application_id_is_valid           (<em class="parameter"><code>const <a href="../glib/glib-Basic-Types.html#gchar"><span class="type">gchar</span></a> *application_id</code></em>);</pre>
<p>
Checks if <em class="parameter"><code>application_id</code></em> is a valid application identifier.
</p>
<p>
A valid ID is required for calls to <a class="link" href="gio-GApplication.html#g-application-new" title="g_application_new ()"><code class="function">g_application_new()</code></a> and
<a class="link" href="gio-GApplication.html#g-application-set-application-id" title="g_application_set_application_id ()"><code class="function">g_application_set_application_id()</code></a>.
</p>
<p>
For convenience, the restrictions on application identifiers are
reproduced here:
</p>
<div class="itemizedlist"><ul class="itemizedlist" type="disc">
<li class="listitem">Application identifiers must contain only the ASCII characters "[A-Z][a-z][0-9]_-." and must not begin with a digit.</li>
<li class="listitem">Application identifiers must contain at least one '.' (period) character (and thus at least three elements).</li>
<li class="listitem">Application identifiers must not begin or end with a '.' (period) character.</li>
<li class="listitem">Application identifiers must not contain consecutive '.' (period) characters.</li>
<li class="listitem">Application identifiers must not exceed 255 characters.</li>
</ul></div>
<p>
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>application_id</code></em> :</span></p></td>
<td>a potential application identifier</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td>
<a href="../glib/glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> if <em class="parameter"><code>application_id</code></em> is valid</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2">
<a name="g-application-new"></a><h3>g_application_new ()</h3>
<pre class="programlisting"><a class="link" href="gio-GApplication.html#GApplication" title="GApplication"><span class="returnvalue">GApplication</span></a> *           g_application_new              (<em class="parameter"><code>const <a href="../glib/glib-Basic-Types.html#gchar"><span class="type">gchar</span></a> *application_id</code></em>,
                                                         <em class="parameter"><code><a class="link" href="gio-GApplication.html#GApplicationFlags" title="enum GApplicationFlags"><span class="type">GApplicationFlags</span></a> flags</code></em>);</pre>
<p>
Creates a new <a class="link" href="gio-GApplication.html#GApplication" title="GApplication"><span class="type">GApplication</span></a> instance.
</p>
<p>
This function calls <a href="../gobject/gobject-Type-Information.html#g-type-init"><code class="function">g_type_init()</code></a> for you.
</p>
<p>
The application id must be valid.  See <a class="link" href="gio-GApplication.html#g-application-id-is-valid" title="g_application_id_is_valid ()"><code class="function">g_application_id_is_valid()</code></a>.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>application_id</code></em> :</span></p></td>
<td>the application id</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>flags</code></em> :</span></p></td>
<td>the application flags</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td>a new <a class="link" href="gio-GApplication.html#GApplication" title="GApplication"><span class="type">GApplication</span></a> instance</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2">
<a name="g-application-get-application-id"></a><h3>g_application_get_application_id ()</h3>
<pre class="programlisting">const <a href="../glib/glib-Basic-Types.html#gchar"><span class="returnvalue">gchar</span></a> *            g_application_get_application_id
                                                        (<em class="parameter"><code><a class="link" href="gio-GApplication.html#GApplication" title="GApplication"><span class="type">GApplication</span></a> *application</code></em>);</pre>
<p>
Gets the unique identifier for <em class="parameter"><code>application</code></em>.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>application</code></em> :</span></p></td>
<td>a <a class="link" href="gio-GApplication.html#GApplication" title="GApplication"><span class="type">GApplication</span></a>
</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td>the identifier for <em class="parameter"><code>application</code></em>, owned by <em class="parameter"><code>application</code></em>
</td>
</tr>
</tbody>
</table></div>
<p class="since">Since 2.28</p>
</div>
<hr>
<div class="refsect2">
<a name="g-application-set-application-id"></a><h3>g_application_set_application_id ()</h3>
<pre class="programlisting"><span class="returnvalue">void</span>                g_application_set_application_id    (<em class="parameter"><code><a class="link" href="gio-GApplication.html#GApplication" title="GApplication"><span class="type">GApplication</span></a> *application</code></em>,
                                                         <em class="parameter"><code>const <a href="../glib/glib-Basic-Types.html#gchar"><span class="type">gchar</span></a> *application_id</code></em>);</pre>
<p>
Sets the unique identifier for <em class="parameter"><code>application</code></em>.
</p>
<p>
The application id can only be modified if <em class="parameter"><code>application</code></em> has not yet
been registered.
</p>
<p>
The application id must be valid.  See <a class="link" href="gio-GApplication.html#g-application-id-is-valid" title="g_application_id_is_valid ()"><code class="function">g_application_id_is_valid()</code></a>.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>application</code></em> :</span></p></td>
<td>a <a class="link" href="gio-GApplication.html#GApplication" title="GApplication"><span class="type">GApplication</span></a>
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>application_id</code></em> :</span></p></td>
<td>the identifier for <em class="parameter"><code>application</code></em>
</td>
</tr>
</tbody>
</table></div>
<p class="since">Since 2.28</p>
</div>
<hr>
<div class="refsect2">
<a name="g-application-get-inactivity-timeout"></a><h3>g_application_get_inactivity_timeout ()</h3>
<pre class="programlisting"><a href="../glib/glib-Basic-Types.html#guint"><span class="returnvalue">guint</span></a>               g_application_get_inactivity_timeout
                                                        (<em class="parameter"><code><a class="link" href="gio-GApplication.html#GApplication" title="GApplication"><span class="type">GApplication</span></a> *application</code></em>);</pre>
<p>
Gets the current inactivity timeout for the application.
</p>
<p>
This is the amount of time (in milliseconds) after the last call to
<a class="link" href="gio-GApplication.html#g-application-release" title="g_application_release ()"><code class="function">g_application_release()</code></a> before the application stops running.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>application</code></em> :</span></p></td>
<td>a <a class="link" href="gio-GApplication.html#GApplication" title="GApplication"><span class="type">GApplication</span></a>
</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td>the timeout, in milliseconds</td>
</tr>
</tbody>
</table></div>
<p class="since">Since 2.28</p>
</div>
<hr>
<div class="refsect2">
<a name="g-application-set-inactivity-timeout"></a><h3>g_application_set_inactivity_timeout ()</h3>
<pre class="programlisting"><span class="returnvalue">void</span>                g_application_set_inactivity_timeout
                                                        (<em class="parameter"><code><a class="link" href="gio-GApplication.html#GApplication" title="GApplication"><span class="type">GApplication</span></a> *application</code></em>,
                                                         <em class="parameter"><code><a href="../glib/glib-Basic-Types.html#guint"><span class="type">guint</span></a> inactivity_timeout</code></em>);</pre>
<p>
Sets the current inactivity timeout for the application.
</p>
<p>
This is the amount of time (in milliseconds) after the last call to
<a class="link" href="gio-GApplication.html#g-application-release" title="g_application_release ()"><code class="function">g_application_release()</code></a> before the application stops running.
</p>
<p>
This call has no side effects of its own.  The value set here is only
used for next time <a class="link" href="gio-GApplication.html#g-application-release" title="g_application_release ()"><code class="function">g_application_release()</code></a> drops the use count to
zero.  Any timeouts currently in progress are not impacted.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>application</code></em> :</span></p></td>
<td>a <a class="link" href="gio-GApplication.html#GApplication" title="GApplication"><span class="type">GApplication</span></a>
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>inactivity_timeout</code></em> :</span></p></td>
<td>the timeout, in milliseconds</td>
</tr>
</tbody>
</table></div>
<p class="since">Since 2.28</p>
</div>
<hr>
<div class="refsect2">
<a name="g-application-get-flags"></a><h3>g_application_get_flags ()</h3>
<pre class="programlisting"><a class="link" href="gio-GApplication.html#GApplicationFlags" title="enum GApplicationFlags"><span class="returnvalue">GApplicationFlags</span></a>   g_application_get_flags             (<em class="parameter"><code><a class="link" href="gio-GApplication.html#GApplication" title="GApplication"><span class="type">GApplication</span></a> *application</code></em>);</pre>
<p>
Gets the flags for <em class="parameter"><code>application</code></em>.
</p>
<p>
See <a class="link" href="gio-GApplication.html#GApplicationFlags" title="enum GApplicationFlags"><span class="type">GApplicationFlags</span></a>.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>application</code></em> :</span></p></td>
<td>a <a class="link" href="gio-GApplication.html#GApplication" title="GApplication"><span class="type">GApplication</span></a>
</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td>the flags for <em class="parameter"><code>application</code></em>
</td>
</tr>
</tbody>
</table></div>
<p class="since">Since 2.28</p>
</div>
<hr>
<div class="refsect2">
<a name="g-application-set-flags"></a><h3>g_application_set_flags ()</h3>
<pre class="programlisting"><span class="returnvalue">void</span>                g_application_set_flags             (<em class="parameter"><code><a class="link" href="gio-GApplication.html#GApplication" title="GApplication"><span class="type">GApplication</span></a> *application</code></em>,
                                                         <em class="parameter"><code><a class="link" href="gio-GApplication.html#GApplicationFlags" title="enum GApplicationFlags"><span class="type">GApplicationFlags</span></a> flags</code></em>);</pre>
<p>
Sets the flags for <em class="parameter"><code>application</code></em>.
</p>
<p>
The flags can only be modified if <em class="parameter"><code>application</code></em> has not yet been
registered.
</p>
<p>
See <a class="link" href="gio-GApplication.html#GApplicationFlags" title="enum GApplicationFlags"><span class="type">GApplicationFlags</span></a>.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>application</code></em> :</span></p></td>
<td>a <a class="link" href="gio-GApplication.html#GApplication" title="GApplication"><span class="type">GApplication</span></a>
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>flags</code></em> :</span></p></td>
<td>the flags for <em class="parameter"><code>application</code></em>
</td>
</tr>
</tbody>
</table></div>
<p class="since">Since 2.28</p>
</div>
<hr>
<div class="refsect2">
<a name="g-application-set-action-group"></a><h3>g_application_set_action_group ()</h3>
<pre class="programlisting"><span class="returnvalue">void</span>                g_application_set_action_group      (<em class="parameter"><code><a class="link" href="gio-GApplication.html#GApplication" title="GApplication"><span class="type">GApplication</span></a> *application</code></em>,
                                                         <em class="parameter"><code><a class="link" href="gio-GActionGroup.html#GActionGroup" title="GActionGroup"><span class="type">GActionGroup</span></a> *action_group</code></em>);</pre>
<p>
Sets or unsets the group of actions associated with the application.
</p>
<p>
These actions are the actions that can be remotely invoked.
</p>
<p>
It is an error to call this function after the application has been
registered.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>application</code></em> :</span></p></td>
<td>a <a class="link" href="gio-GApplication.html#GApplication" title="GApplication"><span class="type">GApplication</span></a>
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>action_group</code></em> :</span></p></td>
<td>a <a class="link" href="gio-GActionGroup.html#GActionGroup" title="GActionGroup"><span class="type">GActionGroup</span></a>, or <a href="../glib/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>. <span class="annotation">[<acronym title="NULL is ok, both for passing and for returning."><span class="acronym">allow-none</span></acronym>]</span>
</td>
</tr>
</tbody>
</table></div>
<p class="since">Since 2.28</p>
</div>
<hr>
<div class="refsect2">
<a name="g-application-get-is-registered"></a><h3>g_application_get_is_registered ()</h3>
<pre class="programlisting"><a href="../glib/glib-Basic-Types.html#gboolean"><span class="returnvalue">gboolean</span></a>            g_application_get_is_registered     (<em class="parameter"><code><a class="link" href="gio-GApplication.html#GApplication" title="GApplication"><span class="type">GApplication</span></a> *application</code></em>);</pre>
<p>
Checks if <em class="parameter"><code>application</code></em> is registered.
</p>
<p>
An application is registered if <a class="link" href="gio-GApplication.html#g-application-register" title="g_application_register ()"><code class="function">g_application_register()</code></a> has been
successfully called.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>application</code></em> :</span></p></td>
<td>a <a class="link" href="gio-GApplication.html#GApplication" title="GApplication"><span class="type">GApplication</span></a>
</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td>
<a href="../glib/glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> if <em class="parameter"><code>application</code></em> is registered</td>
</tr>
</tbody>
</table></div>
<p class="since">Since 2.28</p>
</div>
<hr>
<div class="refsect2">
<a name="g-application-get-is-remote"></a><h3>g_application_get_is_remote ()</h3>
<pre class="programlisting"><a href="../glib/glib-Basic-Types.html#gboolean"><span class="returnvalue">gboolean</span></a>            g_application_get_is_remote         (<em class="parameter"><code><a class="link" href="gio-GApplication.html#GApplication" title="GApplication"><span class="type">GApplication</span></a> *application</code></em>);</pre>
<p>
Checks if <em class="parameter"><code>application</code></em> is remote.
</p>
<p>
If <em class="parameter"><code>application</code></em> is remote then it means that another instance of
application already exists (the 'primary' instance).  Calls to
perform actions on <em class="parameter"><code>application</code></em> will result in the actions being
performed by the primary instance.
</p>
<p>
The value of this property can not be accessed before
<a class="link" href="gio-GApplication.html#g-application-register" title="g_application_register ()"><code class="function">g_application_register()</code></a> has been called.  See
<a class="link" href="gio-GApplication.html#g-application-get-is-registered" title="g_application_get_is_registered ()"><code class="function">g_application_get_is_registered()</code></a>.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>application</code></em> :</span></p></td>
<td>a <a class="link" href="gio-GApplication.html#GApplication" title="GApplication"><span class="type">GApplication</span></a>
</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td>
<a href="../glib/glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> if <em class="parameter"><code>application</code></em> is remote</td>
</tr>
</tbody>
</table></div>
<p class="since">Since 2.28</p>
</div>
<hr>
<div class="refsect2">
<a name="g-application-register"></a><h3>g_application_register ()</h3>
<pre class="programlisting"><a href="../glib/glib-Basic-Types.html#gboolean"><span class="returnvalue">gboolean</span></a>            g_application_register              (<em class="parameter"><code><a class="link" href="gio-GApplication.html#GApplication" title="GApplication"><span class="type">GApplication</span></a> *application</code></em>,
                                                         <em class="parameter"><code><a class="link" href="gio-GCancellable.html#GCancellable" title="GCancellable"><span class="type">GCancellable</span></a> *cancellable</code></em>,
                                                         <em class="parameter"><code><a href="../glib/glib-Error-Reporting.html#GError"><span class="type">GError</span></a> **error</code></em>);</pre>
<p>
Attempts registration of the application.
</p>
<p>
This is the point at which the application discovers if it is the
primary instance or merely acting as a remote for an already-existing
primary instance.  This is implemented by attempting to acquire the
application identifier as a unique bus name on the session bus using
GDBus.
</p>
<p>
Due to the internal architecture of GDBus, method calls can be
dispatched at any time (even if a main loop is not running).  For
this reason, you must ensure that any object paths that you wish to
register are registered before calling this function.
</p>
<p>
If the application has already been registered then <a href="../glib/glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> is
returned with no work performed.
</p>
<p>
The <span class="type">"startup"</span> signal is emitted if registration succeeds
and <em class="parameter"><code>application</code></em> is the primary instance.
</p>
<p>
In the event of an error (such as <em class="parameter"><code>cancellable</code></em> being cancelled, or a
failure to connect to the session bus), <a href="../glib/glib-Standard-Macros.html#FALSE:CAPS"><code class="literal">FALSE</code></a> is returned and <em class="parameter"><code>error</code></em>
is set appropriately.
</p>
<p>
Note: the return value of this function is not an indicator that this
instance is or is not the primary instance of the application.  See
<a class="link" href="gio-GApplication.html#g-application-get-is-remote" title="g_application_get_is_remote ()"><code class="function">g_application_get_is_remote()</code></a> for that.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>application</code></em> :</span></p></td>
<td>a <a class="link" href="gio-GApplication.html#GApplication" title="GApplication"><span class="type">GApplication</span></a>
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>cancellable</code></em> :</span></p></td>
<td>a <a class="link" href="gio-GCancellable.html#GCancellable" title="GCancellable"><span class="type">GCancellable</span></a>, or <a href="../glib/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>error</code></em> :</span></p></td>
<td>a pointer to a NULL <a href="../glib/glib-Error-Reporting.html#GError"><span class="type">GError</span></a>, or <a href="../glib/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>
</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td>
<a href="../glib/glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> if registration succeeded</td>
</tr>
</tbody>
</table></div>
<p class="since">Since 2.28</p>
</div>
<hr>
<div class="refsect2">
<a name="g-application-hold"></a><h3>g_application_hold ()</h3>
<pre class="programlisting"><span class="returnvalue">void</span>                g_application_hold                  (<em class="parameter"><code><a class="link" href="gio-GApplication.html#GApplication" title="GApplication"><span class="type">GApplication</span></a> *application</code></em>);</pre>
<p>
Increases the use count of <em class="parameter"><code>application</code></em>.
</p>
<p>
Use this function to indicate that the application has a reason to
continue to run.  For example, <a class="link" href="gio-GApplication.html#g-application-hold" title="g_application_hold ()"><code class="function">g_application_hold()</code></a> is called by GTK+ 
when a toplevel window is on the screen.
</p>
<p>
To cancel the hold, call <a class="link" href="gio-GApplication.html#g-application-release" title="g_application_release ()"><code class="function">g_application_release()</code></a>.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody><tr>
<td><p><span class="term"><em class="parameter"><code>application</code></em> :</span></p></td>
<td>a <a class="link" href="gio-GApplication.html#GApplication" title="GApplication"><span class="type">GApplication</span></a>
</td>
</tr></tbody>
</table></div>
</div>
<hr>
<div class="refsect2">
<a name="g-application-release"></a><h3>g_application_release ()</h3>
<pre class="programlisting"><span class="returnvalue">void</span>                g_application_release               (<em class="parameter"><code><a class="link" href="gio-GApplication.html#GApplication" title="GApplication"><span class="type">GApplication</span></a> *application</code></em>);</pre>
<p>
Decrease the use count of <em class="parameter"><code>application</code></em>.
</p>
<p>
When the use count reaches zero, the application will stop running.
</p>
<p>
Never call this function except to cancel the effect of a previous
call to <a class="link" href="gio-GApplication.html#g-application-hold" title="g_application_hold ()"><code class="function">g_application_hold()</code></a>.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody><tr>
<td><p><span class="term"><em class="parameter"><code>application</code></em> :</span></p></td>
<td>a <a class="link" href="gio-GApplication.html#GApplication" title="GApplication"><span class="type">GApplication</span></a>
</td>
</tr></tbody>
</table></div>
</div>
<hr>
<div class="refsect2">
<a name="g-application-activate"></a><h3>g_application_activate ()</h3>
<pre class="programlisting"><span class="returnvalue">void</span>                g_application_activate              (<em class="parameter"><code><a class="link" href="gio-GApplication.html#GApplication" title="GApplication"><span class="type">GApplication</span></a> *application</code></em>);</pre>
<p>
Activates the application.
</p>
<p>
In essence, this results in the <a class="link" href="gio-GApplication.html#GApplication" title="GApplication"><span class="type">GApplication</span></a>::<code class="function">activate()</code> signal being
emitted in the primary instance.
</p>
<p>
The application must be registered before calling this function.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody><tr>
<td><p><span class="term"><em class="parameter"><code>application</code></em> :</span></p></td>
<td>a <a class="link" href="gio-GApplication.html#GApplication" title="GApplication"><span class="type">GApplication</span></a>
</td>
</tr></tbody>
</table></div>
<p class="since">Since 2.28</p>
</div>
<hr>
<div class="refsect2">
<a name="g-application-open"></a><h3>g_application_open ()</h3>
<pre class="programlisting"><span class="returnvalue">void</span>                g_application_open                  (<em class="parameter"><code><a class="link" href="gio-GApplication.html#GApplication" title="GApplication"><span class="type">GApplication</span></a> *application</code></em>,
                                                         <em class="parameter"><code><a class="link" href="gio-GFile.html#GFile" title="GFile"><span class="type">GFile</span></a> **files</code></em>,
                                                         <em class="parameter"><code><a href="../glib/glib-Basic-Types.html#gint"><span class="type">gint</span></a> n_files</code></em>,
                                                         <em class="parameter"><code>const <a href="../glib/glib-Basic-Types.html#gchar"><span class="type">gchar</span></a> *hint</code></em>);</pre>
<p>
Opens the given files.
</p>
<p>
In essence, this results in the <span class="type">"open"</span> signal being emitted
in the primary instance.
</p>
<p>
<em class="parameter"><code>n_files</code></em> must be greater than zero.
</p>
<p>
<em class="parameter"><code>hint</code></em> is simply passed through to the ::open signal.  It is
intended to be used by applications that have multiple modes for
opening files (eg: "view" vs "edit", etc).  Unless you have a need
for this functionality, you should use "".
</p>
<p>
The application must be registered before calling this function
and it must have the <a class="link" href="gio-GApplication.html#G-APPLICATION-HANDLES-OPEN:CAPS"><code class="literal">G_APPLICATION_HANDLES_OPEN</code></a> flag set.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>application</code></em> :</span></p></td>
<td>a <a class="link" href="gio-GApplication.html#GApplication" title="GApplication"><span class="type">GApplication</span></a>
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>files</code></em> :</span></p></td>
<td>an array of <a href="gio-GFile.html#GFile"><span class="type">GFiles</span></a> to open. <span class="annotation">[<acronym title="Parameter points to an array of items."><span class="acronym">array</span></acronym> length=n_files]</span>
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>n_files</code></em> :</span></p></td>
<td>the length of the <em class="parameter"><code>files</code></em> array</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>hint</code></em> :</span></p></td>
<td>a hint (or ""), but never <a href="../glib/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>
</td>
</tr>
</tbody>
</table></div>
<p class="since">Since 2.28</p>
</div>
<hr>
<div class="refsect2">
<a name="g-application-run"></a><h3>g_application_run ()</h3>
<pre class="programlisting"><span class="returnvalue">int</span>                 g_application_run                   (<em class="parameter"><code><a class="link" href="gio-GApplication.html#GApplication" title="GApplication"><span class="type">GApplication</span></a> *application</code></em>,
                                                         <em class="parameter"><code><span class="type">int</span> argc</code></em>,
                                                         <em class="parameter"><code><span class="type">char</span> **argv</code></em>);</pre>
<p>
Runs the application.
</p>
<p>
This function is intended to be run from <code class="function">main()</code> and its return value
is intended to be returned by <code class="function">main()</code>. Although you are expected to pass
the <em class="parameter"><code>argc</code></em>, <em class="parameter"><code>argv</code></em> parameters from <code class="function">main()</code> to this function, it is possible
to pass <a href="../glib/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> if <em class="parameter"><code>argv</code></em> is not available or commandline handling is not
required.
</p>
<p>
First, the <code class="function">local_command_line()</code> virtual function is invoked.
This function always runs on the local instance. It gets passed a pointer
to a <a href="../glib/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>-terminated copy of <em class="parameter"><code>argv</code></em> and is expected to remove the arguments
that it handled (shifting up remaining arguments). See
<a class="xref" href="gio-GApplicationCommandLine.html#gapplication-example-cmdline2" title="Example 16. Split commandline handling">Example 16, “Split commandline handling”</a> for an example of
parsing <em class="parameter"><code>argv</code></em> manually. Alternatively, you may use the <a href="../glib/glib-Commandline-option-parser.html#GOptionContext"><span class="type">GOptionContext</span></a> API,
after setting <code class="literal">argc = g_strv_length (argv);</code>.
</p>
<p>
The last argument to <code class="function">local_command_line()</code> is a pointer to the <em class="parameter"><code>status</code></em>
variable which can used to set the exit status that is returned from
<a class="link" href="gio-GApplication.html#g-application-run" title="g_application_run ()"><code class="function">g_application_run()</code></a>.
</p>
<p>
If <code class="function">local_command_line()</code> returns <a href="../glib/glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a>, the command line is expected
to be completely handled, including possibly registering as the primary
instance, calling <a class="link" href="gio-GApplication.html#g-application-activate" title="g_application_activate ()"><code class="function">g_application_activate()</code></a> or <a class="link" href="gio-GApplication.html#g-application-open" title="g_application_open ()"><code class="function">g_application_open()</code></a>, etc.
</p>
<p>
If <code class="function">local_command_line()</code> returns <a href="../glib/glib-Standard-Macros.html#FALSE:CAPS"><code class="literal">FALSE</code></a> then the application is registered
and the <span class="type">"command-line"</span> signal is emitted in the primary
instance (which may or may not be this instance). The signal handler
gets passed a <span class="type">GApplicationCommandline</span> object that (among other things)
contains the remaining commandline arguments that have not been handled
by <code class="function">local_command_line()</code>.
</p>
<p>
If the application has the <a class="link" href="gio-GApplication.html#G-APPLICATION-HANDLES-COMMAND-LINE:CAPS"><code class="literal">G_APPLICATION_HANDLES_COMMAND_LINE</code></a>
flag set then the default implementation of <code class="function">local_command_line()</code>
always returns <a href="../glib/glib-Standard-Macros.html#FALSE:CAPS"><code class="literal">FALSE</code></a> immediately, resulting in the commandline
always being handled in the primary instance.
</p>
<p>
Otherwise, the default implementation of <code class="function">local_command_line()</code> tries
to do a couple of things that are probably reasonable for most
applications.  First, <a class="link" href="gio-GApplication.html#g-application-register" title="g_application_register ()"><code class="function">g_application_register()</code></a> is called to attempt
to register the application.  If that works, then the command line
arguments are inspected.  If no commandline arguments are given, then
<a class="link" href="gio-GApplication.html#g-application-activate" title="g_application_activate ()"><code class="function">g_application_activate()</code></a> is called.  If commandline arguments are
given and the <a class="link" href="gio-GApplication.html#G-APPLICATION-HANDLES-OPEN:CAPS"><code class="literal">G_APPLICATION_HANDLES_OPEN</code></a> flag is set then they
are assumed to be filenames and <a class="link" href="gio-GApplication.html#g-application-open" title="g_application_open ()"><code class="function">g_application_open()</code></a> is called.
</p>
<p>
If you need to handle commandline arguments that are not filenames,
and you don't mind commandline handling to happen in the primary
instance, you should set <code class="literal">G_APPLICATION_HANDLED_COMMAND_LINE</code> and
process the commandline arguments in your <span class="type">"command-line"</span>
signal handler, either manually or using the <a href="../glib/glib-Commandline-option-parser.html#GOptionContext"><span class="type">GOptionContext</span></a> API.
</p>
<p>
If you are interested in doing more complicated local handling of the
commandline then you should implement your own <a class="link" href="gio-GApplication.html#GApplication" title="GApplication"><span class="type">GApplication</span></a> subclass
and override <code class="function">local_command_line()</code>. In this case, you most likely want
to return <a href="../glib/glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> from your <code class="function">local_command_line()</code> implementation to
suppress the default handling. See
<a class="xref" href="gio-GApplicationCommandLine.html#gapplication-example-cmdline2" title="Example 16. Split commandline handling">Example 16, “Split commandline handling”</a> for an example.
</p>
<p>
If, after the above is done, the use count of the application is zero
then the exit status is returned immediately.  If the use count is
non-zero then the mainloop is run until the use count falls to zero,
at which point 0 is returned.
</p>
<p>
If the <a class="link" href="gio-GApplication.html#G-APPLICATION-IS-SERVICE:CAPS"><code class="literal">G_APPLICATION_IS_SERVICE</code></a> flag is set, then the exiting at
use count of zero is delayed for a while (ie: the instance stays
around to provide its <span class="emphasis"><em>service</em></span> to others).
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>application</code></em> :</span></p></td>
<td>a <a class="link" href="gio-GApplication.html#GApplication" title="GApplication"><span class="type">GApplication</span></a>
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>argc</code></em> :</span></p></td>
<td>the argc from <code class="function">main()</code> (or 0 if <em class="parameter"><code>argv</code></em> is <a href="../glib/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>)</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>argv</code></em> :</span></p></td>
<td>the argv from <code class="function">main()</code>, or <a href="../glib/glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>. <span class="annotation">[<acronym title="Parameter points to an array of items."><span class="acronym">array</span></acronym> length=argc]</span>
</td>
</tr>
<tr>
<td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
<td>the exit status</td>
</tr>
</tbody>
</table></div>
<p class="since">Since 2.28</p>
</div>
</div>
</div>
<div class="footer">
<hr>
          Generated by GTK-Doc V1.17</div>
</body>
</html>